package algorithm.personal.combinationpermutation;

import java.util.ArrayList;

import static algorithm.personal.combinationpermutation.Base.factorial;


public class Combination {

    /**
     *
     * @param arrayList 需要组合的数组
     * @param m 组合的个数
     * @return
     */
    public static ArrayList<String> recursionCombination(ArrayList<String> arrayList,int m) {
        ArrayList<String> result = new ArrayList<>(); // 返回的结果
        if(0 == m){
            result.add("");
            return result;
        }

//        if(1 == m){
//            for (int i = 0; i < arrayList.size(); i++) {
//                result.add(arrayList.get(i));
//            }
//            return result;
//        }else {
//            for (int i = 0; i < combinationSize(m,arrayList.size()); i++) {
////                result.add()
//            }
//            return result;
//        }

        return combination(arrayList,result,m);
    }





    /**
     *
     * @param arrayList 待排序
     * @param result    排序后的结果
     * @param m         排序个数
     * @return result    排序后的结果
     */
    public static ArrayList<String> combination(ArrayList<String> arrayList,ArrayList<String> result,int m) {
//        combination
        if(1 == m){
            for (int i = 0; i < arrayList.size(); i++) {
                result.add(arrayList.get(i));
            }
        }else {

        }

        return result;
    }



    /**
     * 计算组合
     * @param m
     * @param n
     * @return
     */
    public static int combinationSize(int m,int n) {
        return (0 != m) ? factorial(n)/(factorial(m) * factorial(n - m)) : 1;
    }
}
